package com.xu.wemall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xu.wemall.entry.Order;
import com.xu.wemall.mapper.OrderMapper;
import com.xu.wemall.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void createOrder(Long userId, Long orderId, LocalDateTime createTime, String status) {
        Order order = new Order();
        order.setUserId(userId);
        order.setOrderId(orderId);
        order.setCreateTime(createTime);
        order.setStatus(status);
        orderMapper.insert(order);
    }

    @Override
    public List<Order> getOrdersByYear(LocalDateTime startDate, LocalDateTime endDate) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("create_time", startDate, endDate);
        return orderMapper.selectList(queryWrapper);
    }

}

